<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String pageTitle = "Search Result";
%>
<%-- <jsp:include page="../template/header.jsp" flush="true"> --%>
<%-- 	<jsp:param name="pageTitle" value="<%=pageTitle%>" /> --%>
<%-- </jsp:include> --%>
<center>
	<section id="form-container">
		<form method="POST" name="flight"
			action="${pageContext.request.contextPath}/flight/searchmockdb.html">
			<fieldset>
				<legend> Search Flights</legend>
				<table class="tableSearchFlight">
					<tr>
						<td><input type="radio" class="radioBtn" name="typeOfTrip"
							value="roundTrip" ${params.typeOfTrip=='roundTrip'?'checked':''}>Round-trip</td>
						<td><input id="one_way" type="radio" class="radioBtn"
							name="typeOfTrip" value="oneWay"
							${params.typeOfTrip=='oneWay'?'checked':''}>One-way</td>
					</tr>
					<tr>

						<td colspan="2"><label>From</label> <br> <input
							id="from" name="fromLocation" width="500px" class="form-control"
							value="${params.fromLocation}"></td>

						<td colspan="4"><label>To</label><input id="to"
							name="toLocation" width="500px" class="form-control"
							value="${params.toLocation}"></td>
					</tr>
					<tr>
						<td><label>Depart</label><br> <input type="text"
							name="outBound" width="250px" value="${params.outBound}"
							class="datepicker form-control"></td>
						<td><label id="lbReturn">Return</label> <input type="text"
							width="250px" name="inBound" id="txtReturn"
							value="${params.inBound}" class="datepicker form-control">
						</td>

						<td><label>Adult</label> <br> <select name="numAdult"
							class="form-control">
								<option value="1" ${params.numAdult==1 ? 'selected':''}>1</option>
								<option value="2" ${params.numAdult==2 ? 'selected':''}>2</option>
								<option value="3" ${params.numAdult==3 ? 'selected':''}>3</option>
								<option value="4" ${params.numAdult==4 ? 'selected':''}>4</option>
						</select> <br>12+ years</td>
						<td><label>Child</label> <br> <select name="numChild"
							class="form-control">
								<option value="0" ${params.numChild=='0' ? 'selected':''}>0</option>
								<option value="1" ${params.numChild=='1' ? 'selected':''}>1</option>
								<option value="2" ${params.numChild=='2' ? 'selected':''}>2</option>
								<option value="3" ${params.numChild=='3' ? 'selected':''}>3</option>
								<option value="4" ${params.numChild=='4' ? 'selected':''}>4</option>
						</select> <br> under 12</td>
						<td><label>Infant</label> <br> <select name="numInfant"
							class="form-control">
								<option value="0" ${params.numInfant=='0' ? 'selected':''}>0</option>
								<option value="1" ${params.numInfant=='1' ? 'selected':''}>1</option>
								<option value="2" ${params.numInfant=='2' ? 'selected':''}>2</option>
								<option value="3" ${params.numInfant=='3' ? 'selected':''}>3</option>
								<option value="4" ${params.numInfant=='4' ? 'selected':''}>4</option>
						</select> <br> under 2</td>
						<td><label>Max Stop(s)</label> <br> <select
							name="numStop" class="form-control">
								<option value="0" ${params.numStop=='0' ? 'selected':''}>0</option>
								<option value="1" ${params.numStop=='1' ? 'selected':''}>1</option>
								<option value="2" ${params.numStop=='2+' ? 'selected':''}>2+</option>
						</select><br></td>
					</tr>
					<tr align="center" valign="middle">
						<td colspan="2"><input type="text" id="demo-input-airline"
							name="airlines" /></td>
						<td colspan="4">
							<button type="submit" class="btn btn-success">Search</button>
						</td>
					</tr>
				</table>
			</fieldset>
		</form>
	</section>
</center>
<center>
	Sort by: <select id="sortFlights">
		<option>-- Select --</option>
		<option value="airlines">Airlines</option>
		<option value="price">Price</option>
		<option value="stops">Number of stops</option>
	</select>
	<section id="form-container">
		<fieldset id="searchResult">
			<legend>LIST RESULTS</legend>
			<label>Total results: ${fn:length(flights)}</label>
			<c:forEach var="flight" items="${flights}" varStatus="theCount">
				<table class="tableFlightResult">
					<tr>
						<td id="airlines"> 
							<b>${flight.outBound.carriers}</b>
							<br>
							${flight.outBound.departAirports[0].departureTimeByDDMMYY}</td>
						<td id="airlines"><c:if
								test="${params.typeOfTrip == 'roundTrip'}">
								<b>${flight.inBound.carriers}</b>
								<br>
								${flight.inBound.departAirports[0].departureTimeByDDMMYY}
							</c:if></td>
						<td id="price">${flight.price.amount}
							${flight.price.currencyCode}</td>
					</tr>
					<tr>
						<td><b>${flight.outBound.departAirports[0].name}
								(${flight.outBound.departAirports[0].code})</b>
							${flight.outBound.departAirports[0].departureTimeByHHmm} - <b>${flight.outBound.arriveAirports[fn:length(flight.outBound.arriveAirports)-1].name}
								(${flight.outBound.arriveAirports[fn:length(flight.outBound.arriveAirports)-1].code})</b>
							${flight.outBound.arriveAirports[fn:length(flight.outBound.arriveAirports)-1].arrivalTimeByHHmm}

							<br> <c:if test="${flight.outBound.numberStops > 0}">
								<span id="outboundStops"><b>${flight.outBound.numberStops}</b></span> Stop(s)
							</c:if> <c:if test="${flight.outBound.numberStops == 0}">
								<span id="outboundStops"><b>${flight.outBound.numberStops}</b></span> Stop (Direct)
							</c:if> ${flight.outBound.totalDuration} mins <br>
							${flight.outBound.airportsExpanded}</td>

						<td><c:if test="${flight.inBound != null}">
								<b>${flight.inBound.departAirports[0].name}
									(${flight.inBound.departAirports[0].code})</b>
									${flight.inBound.departAirports[0].departureTimeByHHmm}
								 -
								<b>${flight.inBound.arriveAirports[fn:length(flight.inBound.arriveAirports)-1].name}
									(${flight.inBound.arriveAirports[fn:length(flight.inBound.arriveAirports)-1].code})</b> 
									${flight.inBound.arriveAirports[fn:length(flight.inBound.arriveAirports)-1].arrivalTimeByHHmm}
								<br>
								<c:if test="${flight.inBound.numberStops > 0}">
									<span id="inboundStops">${flight.inBound.numberStops}</span> Stop(s)
								</c:if>
								<c:if test="${flight.inBound.numberStops == 0}">
									<span id="inboundStops">${flight.inBound.numberStops}</span> Stop (Direct) 
								</c:if> ${flight.outBound.totalDuration} mins <br>
									${flight.inBound.airportsExpanded}
								
							</c:if></td>
						<td><form:form
								action="${pageContext.request.contextPath}/flight/subcribe.html"
								method="POST">
								<button class="btn btn-success" value="${theCount.index}"
									name="index">Subcribe</button>
							</form:form></td>
					</tr>
				</table>
			</c:forEach>
		</fieldset>
	</section>
</center>
</body>
</html>